package cn.darkhorse.workflow.tool;

import cn.darkhorse.exception.InteractionFailedException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description:
 * @author: mr.wang
 * @time: 2020/7/3 0003 16:08
 */
public class WorkflowConstants {
	
	public final  static String IS_PUBLIC_UNPUBLISHED = "0";
	public final  static String IS_PUBLIC_UNPUBLISHED_T = "未发布";
	public final  static String IS_PUBLIC_PUBLIC  = "1";
	public final  static String IS_PUBLIC_PUBLIC_T = "发布";
	/**
	 * 正常
	 */
	public final  static String NORMAL ="0";
	/**
	 * 删除
	 */
	public final  static String DELETE_TRUE ="1";
	/**
	 * 停用
	 */
	public final  static String STOP ="1";
	/**
	 * 未删除
	 */
	public final  static String DELETE_FALSE = "0";
	
	/**
	 * 抢占
	 */
	public final static String SEIZE = "1";
	/**
	 * 同意
	 */
	public final static int AGREE = 1;
	/**
	 * 不同意
	 */
	public final static int DISAGREE = 2;
	/**
	 * 否决
	 */
	public final static int VETO = 3;
	/**
	 * 过程同意
	 */
	public final static int PROCESS_AGREE = 5;
	
	/**
	 * 不同意或否决，终断审批流程
	 */
	public final static int CONTRACT_EXAMPLE = 1;
	/**
	 * 作废
	 */
	public final static String TO_VOID = "3";
	/**
	 * 待审
	 */
	public final static String PENDING_TRIAL = "0";
	/**
	 * 审核中
	 */
	public final static String UNDER_REVIEW = "1";
	
	/**
	 * 已审
	 */
	public final static String REVIEWED = "2";
	
	
	/**
	 * 不应用
	 */
	public final  static Integer IS_APPLY_NO = 0;
	/**
	 * 应用
	 */
	public final  static Integer IS_APPLY_YES = 1;
	
	/** 用户封禁状态 */
	public static final String USER_DISABLE = "1";
	
	
	
	private  static Pattern p = Pattern.compile("_(\\w)");
	/**
	 *下划线转驼峰
	 */
	public static List<Map<String,Object>> underlineToHump(List<Map<String,Object>> mapList){
		List<Map<String,Object>> list = new ArrayList<>();
		if(mapList==null||mapList.size()==0){
			return new ArrayList<>();
		}
		for(Map<String,Object> li:mapList){
			Map<String,Object> map = underlineToHumpSub(li);
			list.add(map);
		}
		return list;
	}
	
	/**
	 *下划线转驼峰
	 */
	public static Map<String,Object> underlineToHumpSub(Map<String,Object> mp){
		   if(mp==null){
			   return null;
		               }
			Map<String,Object> map = new HashMap<>();
			for (Map.Entry<String, Object> m : mp.entrySet()) {
				final StringBuffer sb = new StringBuffer();
				Matcher mc = p.matcher(m.getKey().toLowerCase());
				while (mc.find()){
					mc.appendReplacement(sb,mc.group(1).toUpperCase());
				}
				mc.appendTail(sb);
				map.put(sb.toString(),m.getValue());
			}
		return map;
	}
	
	public static Date stringTransformationData(String date){
		Date d =null;
		SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
		try {
			d = sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			throw  new InteractionFailedException("时间格式转换错误！");
		}
		return d;
	}
	public static String dateTransformationString(Date date){
		SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
		String format = sdf.format(date);
		return format;
	}
	
	
	
	
	
	
}
